package com.lanxin.auth.controller;

import com.lanxin.auth.dto.LoginDTO;
import com.lanxin.enums.HttpStatusEnum;
import com.lanxin.result.ResponseResult;
import com.lanxin.util.JwtUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @author cyh
 * @create 2025-09-29 10:35
 */
@RestController
@Api(tags = "认证接口")
public class AuthController {

    @Autowired
    private JwtUtil jwtUtil;

    @PostMapping("/login")
    @ApiOperation("登录")
    public ResponseResult<?> login(@RequestBody LoginDTO loginDTO) {
        // 这里应验证用户名密码（比如从数据库查）
        if ("admin".equals(loginDTO.getUsername()) && "123456".equals(loginDTO.getPassword())) {
            String token = jwtUtil.generateToken("1",loginDTO.getUsername());

            Map<String, Object> map = new HashMap<>();;
            map.put("token", token);
            return ResponseResult.success(map);
        } else {
            return ResponseResult.fail("用户名或密码错误");
        }
    }
}
